#!/bin/sh
### BEGIN INIT INFO
# Provides:          rip-sender
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: RIPv2 sender
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DESC="rip-sender daemon"
NAME=rip-sender
DAEMON=/usr/sbin/rip-sender
PIDFILE=/var/run/rip-sender.pid
SCRIPTNAME=/etc/init.d/"$NAME"
CONFIG_OPTS=/etc/rip-sender.conf

test -f $DAEMON || exit 0

. /lib/lsb/init-functions

parse_environment () 
{
    for ENV_FILE in /etc/environment /etc/default/locale; do
        [ -r "$ENV_FILE" ] || continue
        [ -s "$ENV_FILE" ] || continue

         for var in LANG LANGUAGE LC_ALL LC_CTYPE; do
             value=`egrep "^${var}=" "$ENV_FILE" | tail -n1 | cut -d= -f2`
             [ -n "$value" ] && eval export $var=$value

             if [ -n "$value" ] && [ "$ENV_FILE" = /etc/environment ]; then
                 log_warning_msg "/etc/environment has been deprecated for locale information; use /etc/default/locale for $var=$value instead"
             fi
         done
     done

# Get the timezone set.
    if [ -z "$TZ" -a -e /etc/timezone ]; then
        TZ=`cat /etc/timezone` 
    fi
}

# Parse the system's environment
if [ "$READ_ENV" = "yes" ] ; then
    parse_environment
fi


case "$1" in
start)	log_daemon_msg "Starting RIPv2 sender" "rip-sender"
        start_daemon -p $PIDFILE $DAEMON $CONFIG_OPTS
        log_end_msg $?
	;;
stop)	log_daemon_msg "Stopping RIPv2 sender" "rip-sender"
        killproc -p $PIDFILE $DAEMON
        RETVAL=$?
        [ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
        log_end_msg $RETVAL
        ;;
restart) log_daemon_msg "Restarting RIPv2 sender" "rip-sender" 
        $0 stop
        $0 start
        ;;
reload|force-reload) log_daemon_msg "Reloading configuration files for RIPv2 sender" "rip-sender"
	killproc -p $PIDFILE $DAEMON -SIGHUP
        log_end_msg 0
        ;;
status)
        status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
        ;;
*)	log_action_msg "Usage: /etc/init.d/rip-sender {start|stop|status|restart|reload|force-reload}"
        exit 2
        ;;
esac
exit 0
